/*
 * position.cpp
 *
 *  Created on: 11/giu/2014
 *      Author: ammin
 */

#include "position.h"

using namespace NS_STOCKEXCHANGE;

Position::Position(Order &reqOrder, Portfolio *pAssocPF) : m_order(reqOrder){
	m_pAssocPortfolio = pAssocPF;
}

Position::~Position(){

}

TARGET_HIT Position::UpdateCurrentValue(StockData &stockData){
	TARGET_HIT hit = TARGET_NONE;

	m_currentData = stockData;
	PRICE takeProfitPrice = m_order.m_entryPrice * (1 + m_order.m_takeProfit);
	PRICE stopLossPrice = m_order.m_entryPrice * (1 - m_order.m_stopLoss);

	if(takeProfitPrice <= m_currentData.max){
		if(stopLossPrice < m_currentData.min)
			hit = TARGET_TAKE_PROFIT;
		else
			hit = TARGET_AMBIGUITY;
	}

	if(stopLossPrice >= m_currentData.min)
		hit = TARGET_STOP_LOSS;

	return hit;
}

PRICE Position::GetCurrentValue() const{
	return m_order.m_nStock * m_currentData.close;
}
